<!--
 * @Author: your name
 * @Date: 2021-04-03 20:54:35
 * @LastEditTime: 2021-04-03 22:55:09
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \jianfa-admin\src\page\real-time\real-time-list.vue
-->
<template>
  <Container class="code-list">
    <!-- <div id="qrcode"></div>  -->
    <Breadcrumb :navList="$route.meta.nav"></Breadcrumb>
    <avue-crud
      :data="data"
      :option="option"
      @row-save="submit"
      :table-loading="loading"
    >
      <template slot-scope="{ row, type, size }" slot="menu">
        <el-button
          icon="el-icon-plus"
          :size="size"
          :type="type"
          @click="towThreeMenu(row.id)"
          >添加三级菜单</el-button
        >
        <del-button @click="delMenu(row.id)">删除</del-button>
      </template>
    </avue-crud>
  </Container>
</template>
<script>
export default {
  data() {
    return {
      loading: true,
      data: [
        {
          class_name: "二级菜单名称"
        }
      ],
      option: {
        labelWidth: 200,
        delBtn: false,
        editBtn: false,
        page: false,
        align: "center",
        menuAlign: "center",
        column: [
          {
            label: "二级菜单名称",
            prop: "class_name"
          }
        ]
      }
    };
  },
  methods: {
    //   去往三级菜单添加
    towThreeMenu(id) {
      this.$router.push({ path: "/add-ssdt", query: { id } });
    },
    async submit(form, done, loading) {
      if (!form.class_name) {
        this.$message.error("不能为空");
        loading();
        return;
      }
      await this.$api.realTime.addTowMenu(form);
      await this.getMenu();
      done();
    },
    async delMenu(id) {
      this.loading = true;
      const { code, data, msg } = await this.$api.realTime.delTowMenu({ id });
      if (!code) {
        this.$message.success(msg);
        this.getMenu();
      }
    },
    async getMenu() {
      this.loading = true;
      const { code, data } = await this.$api.realTime.getTowMenu();
      this.loading = false;
      if (!code) {
        this.data = data;

        return true;
      }
    }
  },
  created() {
    this.getMenu();
  }
};
</script>
<style lang="scss" scoped></style>
